package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.service.DepReqListInfoService;
import com.softer.wxzj.service.DepositApplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 交存申请
 *
 * @author Gong Zhiyang
 * @date 2019/6/27
 */
@RestController
@RequestMapping("/depositApply")
@Slf4j
public class DepositApplyController {
    @Autowired
    private DepositApplyService depositApplyService;

    @Autowired
    private DepReqListInfoService depReqListInfoService;

    /**
     * 精确/模糊查询 交存申请查询列表
     *
     * @param page           分页实体
     * @param baseRegionInfo 查询实体
     * @param fuzzy          模糊查询字段
     * @return 交存申请查询列表
     */
    @RequestMapping("/getDepositApplyList")
    @LogRecord(description = "交存申请查询列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<BaseRegionInfo> getDepositApplyList(Page page, BaseRegionInfo baseRegionInfo, String fuzzy) {
        return depositApplyService.getDepositApplyList(page, baseRegionInfo, fuzzy);
    }

    /**
     * 精确/模糊查询 根据申请ID查询申请明细
     *
     * @param page         分页实体
     * @param depositAudit 查询实体
     * @param fuzzy        模糊查询字段
     * @return 申请明细
     */
    @RequestMapping("/getListByReqId")
    @LogRecord(description = "根据申请ID查询申请明细", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<DepositAudit> getListByReqId(Page page, DepositAudit depositAudit, String fuzzy) {
        return depositApplyService.getListByReqId(page, depositAudit, fuzzy);
    }

    /**
     * 批量查询交存清册
     *
     * @param page 分页实体
     * @param reqIdList 交存申请ID集合
     * @return 清册列表
     */
    @RequestMapping("/batchPrintList")
    @LogRecord(description = "批量查询交存清册", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PrintList batchPrintList(Page page, String reqIdList) {
        return depositApplyService.batchPrintList(page,reqIdList);
    }

    /**
     * 精确/模糊查询 根据申请ID查询申请明细的本页合计和总合计
     *
     * @param page         分页实体
     * @param depositAudit 查询实体
     * @param fuzzy        模糊查询字段
     * @return 申请明细的本页合计和总合计
     */
    @RequestMapping("/getTotalByReqId")
    @LogRecord(description = "根据申请ID查询申请明细的本页合计和总合计", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public List<DepositAudit> getTotalByReqId(Page page, DepositAudit depositAudit, String fuzzy) {
        return depositApplyService.getTotalByReqId(page, depositAudit, fuzzy);
    }

    /**
     * 精确/模糊查询 根据小区ID查询申请列表
     *
     * @param page         分页实体
     * @param depositApply 查询实体
     * @param fuzzy      模糊查询字段
     * @return 申请列表
     */
    @RequestMapping("/getListByRegionId")
    @LogRecord(description = "根据小区ID查询申请列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<DepositApply> getListByRegionId(Page page, DepositApply depositApply, String fuzzy) {
        return depositApplyService.getListByRegionId(page, depositApply, fuzzy);
    }

    /**
     * 查询代缴企业列表
     *
     * @param id 小区ID
     * @return 企业列表
     */
    @RequestMapping("/getOrganization")
    @LogRecord(description = "查询代缴企业列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public List<BaseOrganization> getOrganization(String id) {
        return depositApplyService.getOrganization(id);
    }

    /**
     * 精确/模糊查询业主自交列表或者企业代缴申请列表
     *
     * @param page         分页实体
     * @param depositAudit 查询实体
     * @param fuzzy        模糊查询字段
     * @return 申请列表
     */
    @RequestMapping("/getDepositApplyListByRegionId")
    @LogRecord(description = "查询业主自交列表或者企业代缴申请列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<DepositAudit> getDepositApplyListByRegionId(Page page, DepositAudit depositAudit, String fuzzy) {
        return depositApplyService.getDepositApplyListByRegionId(page, depositAudit, fuzzy);
    }

    /**
     * 交存申请
     *
     * @param depositAuditReceive list      申请id列表
     *                            type      交存模式（00 为自缴 01为企业代缴）
     *                            validDate 申请有效日期
     *                            corpNo    开发商ID
     * @return 交存结果
     */
    @RequestMapping("/depositAudit")
    @LogRecord(description = "交存申请", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.INSERT)
    public CommonResult depositAudit(@RequestBody DepositAuditReceive depositAuditReceive) {
        return depositApplyService.depositAudit(depositAuditReceive.getList(), depositAuditReceive.getType(), depositAuditReceive.getValidDate(), depositAuditReceive.getCorpNo());
    }

    /**
     * 获取刚交存申请的打印通知单列表
     *
     * @param list 申请id列表
     * @return 打印通知单列表
     */
    @RequestMapping("/getPrintList")
    @LogRecord(description = "打印通知单列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public List<DepositAudit> getPrintList(@RequestBody List<String> list) {
        return depositApplyService.getPrintList(list);
    }

    /**
     * ludexing
     * todo
     *
     * @param startNo
     * @param endNo
     * @param startWith
     * @return
     */
    @LogRecord(description = "修改凭证编号", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.UPDATE)
    @RequestMapping("/updateDepositApplyNo")
    public CommonResult updateDepositApplyNo(String startNo, String endNo, String startWith) {
        return depositApplyService.updateDepositApplyNo(startNo, endNo, startWith);
    }

    /**
     * 批量撤销 申请  1,2,3
     * ludexing
     */
    @RequestMapping("/depositApplyRevocation")
    @LogRecord(description = "批量撤销申请", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.UPDATE)
    public CommonResult depositApplyRevocation(String depositApplyIds) {
        return depositApplyService.depositApplyRevocation(depositApplyIds);
    }


    /**
     * 所有撤销了的
     * ludexing
     *
     * @param page
     * @return
     */
    @LogRecord(description = "撤销记录列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.UPDATE)
    @RequestMapping("/findRevocationList")
    public PageInfo<List<Map>> findRevocationList(Page page, DepositApply depositApply, String fuzzy) {
        return depReqListInfoService.findRevocationList(page, depositApply, fuzzy);
    }

    /**
     * 撤销查看
     * ludexing
     *
     * @param id
     * @return
     */
    @RequestMapping("/getRevocationInfo")
    @LogRecord(description = "撤销查看", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.UPDATE)
    public PageInfo<DepositAudit> getRevocationInfo(Page page, String id) {
        return depReqListInfoService.getRevocationInfo(page, id);
    }
    /**
     * 撤销查看
     * ludexing
     *
     * @param id
     * @return
     */
    @RequestMapping("/findRevocationListDep")
    @LogRecord(description = "撤销查看", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.UPDATE)
    public PageInfo<DepReq> findRevocationListDep(Page page, DepReq depReq) {
        return depReqListInfoService.findRevocationListDep(page, depReq);
    }


    /**
     * DepositApply 实体的 getlist方法 两个查询
     *
     * @param page
     * @param depositApply
     * @return 打印 通用列表
     * @Author ludexing
     */
    @RequestMapping("/findDepositApplyList")
    @LogRecord(description = "申请撤销列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<DepositApply> findDepositApplyList(Page page, DepositApply depositApply) {
        return depositApplyService.findDepositApplyList(page, depositApply);
    }

    /**
     * @param depositApply
     * @return
     * @Author ludexing
     */
    @LogRecord(description = "更新申请有效期", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.UPDATE)
    @RequestMapping("/updateApplyCValidDate")
    public CommonResult updateApplyCValidDate(DepositApply depositApply) {
        return depositApplyService.updateValidDate(depositApply);
    }

    /**
     * 通知书打印
     * 补打和交存凭证打印，查询的是所有记账后的数据，state=4；
     * 交存通知打印，查询的是申请后，未记账的数据，state=3
     *
     * @param page         分页实体
     * @param depositApply 查询实体
     * @return 打印列表
     */
    @RequestMapping("/printNotice")
    @LogRecord(description = "通知书打印列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<DepositApply> printNotice(Page page, DepositApply depositApply) {
        return depositApplyService.printNotice(page, depositApply);
    }

    /**
     * 催缴打印列表
     *
     * @param page           分页实体
     * @param baseRegionInfo 查询实体
     * @return 列表
     */
    @RequestMapping("/print/call")
    @LogRecord(description = "催缴打印列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<BaseRegionInfo> printCall(Page page, BaseRegionInfo baseRegionInfo) {
        return depositApplyService.printCall(page, baseRegionInfo);
    }


    /**
     * 根据小区ID查询催缴打印列表
     *
     * @param page          分页实体
     * @param baseHouseInfo 查询实体
     * @return 列表
     */
    @RequestMapping("/printCallByRegionId")
    @LogRecord(description = "根据小区ID查询催缴打印列表", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<BaseHouseInfo> printCallByRegionId(Page page, BaseHouseInfo baseHouseInfo) {
        return depositApplyService.printCallByRegionId(page, baseHouseInfo);
    }

    /**
     * 查询业主自交或企业代缴的日期
     *
     * @param corpType
     * @return
     */
    @RequestMapping("/time")
    @LogRecord(description = "查看申请日期", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public String time(String corpType) {
        return depositApplyService.time(corpType);
    }
/**
 * 资金补齐缴存审核
 */
@RequestMapping("/subimtDepReqList")
@LogRecord(description = "资金补齐缴存审核", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
public PageInfo<DepReq> subimtDepReqList(Page page,DepReq depReq) {
    return depositApplyService.subimtDepReqList(page,depReq);
}
    /**
     * 资金补齐缴存申请查询
     */
    @RequestMapping("/getAllDepReqList")
    @LogRecord(description = "资金补齐缴存申请查询", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public PageInfo<DepReq> getAllDepReqList(Page page,DepReq depReq) {
        return depositApplyService.getAllDepReqList(page,depReq);
    }
    /**
     * 资金补齐申请撤销
     */
    @RequestMapping("/findDeposiy")
    @LogRecord(description = "资金补齐申请撤销", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public CommonResult findDeposiy(String id){
        return depositApplyService.findDeposiy(id);
    }
    /**
     * 资金补齐审核查询
     */
    @RequestMapping("/submitDepList")
    @LogRecord(description = "资金补齐申请撤销", operationUnit = LogOperationUnit.DEPOSIT, operationType = LogOperationType.SELECT)
    public  PageInfo<DepReq> submitDepList(Page page,DepReq depReq){
        return depositApplyService.submitDepList(page,depReq);
    }
}
